package coop.bancocredicoop.proyectos.gd



import static org.springframework.http.HttpStatus.*
import grails.transaction.Transactional
import coop.bancocredicoop.proyectos.gd.command.BuscarClienteCommand
import coop.bancocredicoop.proyectos.gd.crecerxxi.CrecerXXI

@Transactional(readOnly = true)
class BuscarClienteController {

    static allowedMethods = [save: "POST", update: "PUT", delete: "DELETE"]

	def crecerxxiWrapper
	
    def modalIndex() {
		//def listDocument = Document.findAllByCustomer(customer)
        //respond listDocument, model:[documentInstanceCount: listDocument.size()]
    }

	def buscar(BuscarClienteCommand buscarClienteCommand) {
		if (buscarClienteCommand.hasErrors()) {
			return [buscarClienteCommand: buscarClienteCommand]
		}

		if (params.buscarPor == 'idPersona')
			[customerInstanceList: crecerxxiWrapper.findCustomerByIdPersona(params.tipoPersona, params.valor as Long)]
		else if (params.buscarPor == 'cuit')
			[customerInstanceList: crecerxxiWrapper.findCustomerByCuit(params.tipoPersona, params.valor)]
		else
			[customerInstanceList: crecerxxiWrapper.findCustomerByNombre(params.tipoPersona, params.valor)]
	}

}
